'''
Night Elf WCS:Python Race Coded By: J3ff Hoogland
'''
import wcs, es, random, effectlib
from wcs import wcs
#Our Race's Name - This is not needed I just feel it makes things look cleaner
RaceName = 'Night Elf'
wcs.Race(RaceName).registerSkill('Evasion', 5, 2, 'Have a chance to dodge damage from an attack.')
wcs.Race(RaceName).registerSkill('Thorns', 4, 1, 'Have a chance to reflect 30% damage back at your attacker.')
wcs.Race(RaceName).registerSkill('True Shot', 4, 1, 'Have a 30% change to deal bonus damage.')
wcs.Race(RaceName).registerUltimate('Entangle', 7, 3, 2, 'Use your ultimate to stop all nearby enemies from moving.')
def player_hurt(event_var):
	userid = int(event_var['userid'])
	attacker = int(event_var['attacker'])
	damage = int(event_var['dmg_health'])
	evasion = wcs.GetLevel(userid, RaceName, 'Evasion') * 5
	if evasion:
		if evasion >= random.randint(1,100):
			wcs.Command(userid).Heal(damage)
			es.tell(userid, '#multi', '#lightgreenEvasion #default- #greenYou have dodged %s damage from an attack.'%damage)
	thorns = wcs.GetLevel(userid, RaceName, 'Thorns')*15
	if thorns:
		if random.randint(1,100) <= thorns:
			wcs.Command(attacker).Damage(damage*.3,32,userid)
			es.tell(userid, '#multi', '#lightgreenThorns #default- #greenYou have returned %s damage to %s.'%(damage*.3,event_var['es_attackername']))
			effectlib.drawLine(es.getplayerlocation(userid), es.getplayerlocation(attacker), red=0, blue=150)
	trueshot = wcs.GetLevel(attacker, RaceName, 'True Shot') * .15
	if trueshot:
		if random.randint(1,100) <= 30:
			wcs.Command(userid).Damage(damage*trueshot,32,attacker)
			es.tell(attacker, '#multi', '#lightgreenTrue Shot #default- #greenYou have dealt %s extra damage.'%(damage*trueshot))
			effectlib.drawLine(es.getplayerlocation(attacker), es.getplayerlocation(userid))
def player_ultimate_on(event_var):
	userid = int(event_var['userid'])
	team = int(es.getplayerteam(userid))
	if team == 2:
		filter = '#ct'
	elif team == 3:
		filter = '#t'
	entangle = wcs.GetLevel(userid, RaceName, 'Entangle')*6
	if entangle:
		wcs.Command(userid).Near(360,stun,filter)
		wcs.Command(userid).SetCoolDown('Entangle',entangle)
def stun(userid, attacker):
	wcs.Command(userid).Freeze(wcs.GetLevel(attacker, RaceName, 'Entangle')*3)
	effectlib.drawLine(es.getplayerlocation(userid), es.getplayerlocation(attacker), red=0, blue=0)
	es.tell(userid, '#lightgreen', 'You have been entangled!')